package demo.yangxu.springboot.mapper;

import demo.yangxu.springboot.bean.Department;
import org.apache.ibatis.annotations.*;

//指定这是一个操作数据库的mapper
//使用了MapperScan,@Mapper可以注释掉了
//@Mapper
public interface DepartmentMapper {
    @Select("SELECT * FROM department WHERE id=#{id}")
    public Department getDeptById(Integer id);

    @Delete("DELETE FROM department WHERE id=#{id}")
    public int deleteDeptById(Integer id);

    //useGeneratedKeys = true使用自动生成的主键
    //keyProperty = "id" Department中的id属性是用来封装的主键
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("INSERT INTO department(departmentName) VALUES(#{departmentName})")
    public int insertDept(Department department);

    @Update("UPDATE department SET departmentName=#{departmentName} WHERE id=#{id}")
    public int updateDept(Department department);
}
